import javax.crypto.interfaces.PBEKey;
import java.util.Arrays;
import java.util.Comparator;

class MyArray  <T extends Comparable<T> >{

    public T compare(T[] nums) {
        T max = nums[0];
        for(int i=1; i<nums.length; ++i) {
            if(nums[i].compareTo(max)>0) {
                max = nums[i];
            }
        }
        return max;
    }
}

//泛型方法
class Util {
    public static <T> void swap(T[] nums,int i,int j){
        T temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}

public class Test {
    public static void main(String[] args) {
        MyArray array = new MyArray();
        Integer[] arr = {1,2,11,4,5,9};
        System.out.println(array.compare(arr));

        Integer[]   arr2 = {9,18};
        //类型自动推导
        Util.swap(arr2,0,1);
        //类型手动添加
        Util.<Integer>swap(arr2,0,1);
        System.out.println(Arrays.toString(arr2));
    }
}
